package com.shengqi.xinnongren.work.ui.user.activities;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.text.Html;
import android.widget.ImageView;
import android.widget.TextView;

import com.shengqi.xinnongren.R;
import com.shengqi.xinnongren.common.base.BaseMvpActivity;
import com.shengqi.xinnongren.common.utils.ImageUtils;
import com.shengqi.xinnongren.common.utils.ToastHelper;
import com.shengqi.xinnongren.common.utils.ToastUtils;
import com.shengqi.xinnongren.work.ui.user.model.ServiceBean;
import com.shengqi.xinnongren.work.ui.user.presenter.ServicePresenter;
import com.shengqi.xinnongren.work.ui.user.view.ServiceView;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 联系客服
 */
public class ServiceActivity extends BaseMvpActivity<ServiceView, ServicePresenter> implements ServiceView {

    @BindView(R.id.tv_wx_id)
    TextView tvWxId;
    @BindView(R.id.iv_qr_code)
    ImageView ivQrCode;
    @BindView(R.id.tv_scan_qr_code)
    TextView tvScanQrCode;
    private String mWeChat;

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_service;
    }

    @Override
    protected void initView() {
        tvScanQrCode.setText(Html.fromHtml("<font color=\"#aaaaaa\">或</font>" +
                "<font color=\"#f4436d\">微信扫一扫</font>"));
    }

    @Override
    protected void initData() {
        mPresenter.getData();
    }

    @Override
    protected ServicePresenter createPresenter() {
        return new ServicePresenter();
    }


    @Override
    public void showLoadingView() {
        showLoadingDialog();
    }

    @Override
    public void hideLoadingView() {
        hideLoadingDialog();
    }

    @Override
    public void onNetworkError() {
        hideLoadingView();
    }

    @OnClick(R.id.tv_copy)
    public void onCopyClick() {
        ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        if (manager != null) {
            manager.setPrimaryClip(ClipData.newPlainText("text", mWeChat));
            ToastUtils.showShort(this, "已复制");
        }
    }

    @Override
    public void showDataRes(ServiceBean data) {
        mWeChat = data.getWeChat();
        tvWxId.setText("微信ID: " + mWeChat);
        ImageUtils.showImage(this, data.getWeChatQR(), ivQrCode);
    }

    @Override
    public void showRequestFailed(String message) {
        ToastHelper.getInstance(this).showWarn(message);
    }
}
